package com.dbuil.bleshoes.ui.fragment;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.LogUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.dbuil.bleshoes.Constant;
import com.dbuil.bleshoes.R;
import com.dbuil.bleshoes.adapter.ShopItemAdapter;
import com.dbuil.bleshoes.base.BaseFragment;
import com.dbuil.bleshoes.bean.ShopBean;
import com.dbuil.bleshoes.ui.activity.ProductListActivity;
import com.dbuil.bleshoes.ui.activity.ProductDetailActivity;
import com.dbuil.bleshoes.ui.activity.SearchHistoryActivity;
import com.dbuil.bleshoes.ui.activity.GouWuCarActivity;
import com.dbuil.bleshoes.ui.view.NofastClickTextview;
import com.xuexiang.xui.utils.ResUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class ShopFragment extends BaseFragment {

    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.tv_top_title)
    TextView tvTopTitle;
    @BindView(R.id.tv_top_right)
    TextView tvTopRight;
    @BindView(R.id.img_top_right)
    ImageView imgTopRight;
    @BindView(R.id.tv_shop_tosearch)
    NofastClickTextview tvShopTosearch;
    @BindView(R.id.tv_shop_newshoes)
    NofastClickTextview tvShopNewshoes;
    @BindView(R.id.tv_shop_shoes_derive)
    NofastClickTextview tvShopShoesDerive;
    @BindView(R.id.tv_shop_sport_surround)
    NofastClickTextview tvShopSportSurround;
    @BindView(R.id.tv_shop_other)
    NofastClickTextview tvShopOther;
    @BindView(R.id.ll_shop_content)
    LinearLayout llShopContent;
    @BindView(R.id.img_gouwucar)
    ImageView imgGouwucar;

    private List<String> titleList = new ArrayList<>();

    private ShopItemAdapter mAdapter;
    private List<ShopBean> listdata = new ArrayList<>();

    @Override
    public int getLayoutId() {
        return R.layout.fragment_shop;
    }

    @Override
    public void initImmersionBar() {
        //   BarUtil.setWhiteStatusBarForFragment(this);
    }

    @Override
    public void initView() {
        super.initView();
        LogUtils.i(getString(R.string.shop));
    }

    @Override
    public void initData() {
        super.initData();
        tvTopTitle.setText(getString(R.string.shop));
        imgBack.setVisibility(View.GONE);
        String[] stringArray = ResUtils.getStringArray(R.array.shop_title);

        for (String s : stringArray) {
            titleList.add(s);
        }

        for (int i = 0; i < 8; i++) {

            listdata.add(new ShopBean());
        }

        // llShopContent.removeAllViews();
        for (String s : titleList) {
            View inflate = LayoutInflater.from(context).inflate(R.layout.item_shop, null);
            llShopContent.addView(inflate);

            TextView tvShopTitle = inflate.findViewById(R.id.tv_shop_title);
            RecyclerView mRecycle = inflate.findViewById(R.id.recycle_shop_item);
            LinearLayoutManager layoutManager = new LinearLayoutManager(context);
            layoutManager.setOrientation(RecyclerView.HORIZONTAL);
            mRecycle.setLayoutManager(layoutManager);
            mAdapter = new ShopItemAdapter(listdata);
            mAdapter.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {

                    ActivityUtils.startActivity(ProductDetailActivity.class);
                }
            });
            mRecycle.setAdapter(mAdapter);


            tvShopTitle.setText(s);
        }


    }

    @OnClick({R.id.tv_shop_tosearch, R.id.img_gouwucar})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_shop_tosearch:
                ActivityUtils.startActivity(SearchHistoryActivity.class);
                break;
            case R.id.img_gouwucar:
                ActivityUtils.startActivity(GouWuCarActivity.class);
                break;

        }
    }

    @OnClick({R.id.tv_shop_newshoes, R.id.tv_shop_shoes_derive, R.id.tv_shop_sport_surround, R.id.tv_shop_other})
    public void onViewClickedtoProduct(View view) {
        Intent intent = new Intent(context, ProductListActivity.class);
        String producttitle = "";
        switch (view.getId()) {
            case R.id.tv_shop_newshoes:
                producttitle = getString(R.string.newshoes);
                break;
            case R.id.tv_shop_shoes_derive:
                producttitle = getString(R.string.shoesderive);
                break;
            case R.id.tv_shop_sport_surround:
                producttitle = getString(R.string.sportsurround);
                break;
            case R.id.tv_shop_other:
                producttitle = getString(R.string.otherproduct);
                break;
        }

        intent.putExtra(Constant.PRODUCTTITLE, producttitle);
        ActivityUtils.startActivity(intent);
    }
}
